﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chinaer.WCF.Services;

namespace Chinaer.UI.MVC.Controllers
{
    public class AdminController : Controller
    {
        //
        // GET: /Admin/

        public ActionResult Index()
        {
            return View();
        }

        public ContentResult GetAllAdministrators()
        {
            ChinaerService chinaerService = new ChinaerService();
            List<DTO.AdministratorDTO> listCountry = chinaerService.GetAllAdministrators("");
            string jsonResult = Helper.JsonHelper.GetJson(listCountry, listCountry.Count);
            //return new JsonResult()
            //{
            //    Data = jsonResult,
            //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
            //};
            return new ContentResult()
            {
                Content = jsonResult
            };
        }
        [HttpPost]
        public string saveAdministrator(DTO.AdministratorDTO administratorDTO)
        {
            ChinaerService chinaerService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaerService.AddAdministrator(administratorDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        [HttpPost]
        public string updateAdministrator(DTO.AdministratorDTO administratorDTO)
        {
            ChinaerService chinaerService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaerService.UpdateAdministrator(administratorDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        [HttpPost]
        public string DeleteAdministrator(string ID)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.DeleteAdministratorByID(ID);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
    }
}
